package com.playfair.gui;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.playfair.core.AppCore;

public class MainDialog extends JFrame {

	private static final long serialVersionUID = 8989433519219513079L;
	private JButton encryptButton, decryptButton, attackButton;

	public MainDialog() {
		setVisible(true);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setTitle("Playfair");
		setLayout(new GridLayout(1, 3));
		setButtons();
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			e.printStackTrace();
		}
		pack();
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension dim = kit.getScreenSize();
		setLocation((dim.width - getWidth()) / 2,
				(dim.height - getHeight()) / 2);
		setResizable(false);
	}

	private void setButtons() {
		encryptButton = new JButton(AppCore.getInstance().getActionManager()
				.getEncryptAction());
		decryptButton = new JButton(AppCore.getInstance().getActionManager()
				.getDecryptAction());
		attackButton = new JButton(AppCore.getInstance().getActionManager()
				.getBruteForceAttackAction());

		add(encryptButton);
		add(decryptButton);
		add(attackButton);
	}

}
